package com.itrencai.d5_Collection.diedaiqi;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

//迭代器,集合的遍历方式
public class CollactionDemoddq {
    public static void main(String[] args) {
        Collection<String> lists=new ArrayList<>();
        lists.add("赵敏");
        lists.add("小昭");
        lists.add("素素");
        lists.add("灭绝");
        System.out.println(lists);
        //1.得到当前集合的迭代器对象
        Iterator<String> it=lists.iterator();
/*        System.out.println("--------------------------");
        String ele= it.next();
        System.out.println(ele);
        System.out.println("--------------------------");
        System.out.println(it.next());
        System.out.println(it.next());
        System.out.println(it.next());
        //System.out.println(it.next());//访问异常，出现无此元素异常的错误*/

        //2.迭代器定义while循环
        while(it.hasNext()){
            String ele= it.next();
            //System.out.println(ele);
            //迭代器遍历删除
            if("赵敏".equals(ele)){
                it.remove();//使用迭代器删除当前位置的元素，保证不位移，能够成功遍历到全部元素
            }
        }
        System.out.println(lists);
        System.out.println("--------------------------");

        //3.增强for用于集合遍历
        /*for(String ele:lists){
            System.out.println(ele);
        }*/
        double[] arrs={100,99.5,59.5};
        for (double arr : arrs) {
            System.out.println(arr);
        }

        //3.lambda表达式遍历
        Collection<String> scores=new ArrayList<>();
        scores.add("你好");
        scores.add("中国");
        scores.add("结");
        System.out.println(scores);
        scores.forEach(s -> {System.out.println(s); });
        //scores.forEach(System.out::println);



    }
}
